<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="50px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="opera-wrap">
    <button
      nz-button
      nzType="primary"
      (click)="showEditModal()"
    >新增</button>
  </div>

  <div class="pagination-wrap-position p-t-15">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="80px">排序</th>
          <th nzAlign="center" nzWidth="200px">名称</th>
          <th nzAlign="center" nzWidth="160px">标签</th>
          <th nzAlign="center" nzWidth="150px">应用ID</th>
          <th nzAlign="center" nzWidth="170px">开始时间</th>
          <th nzAlign="center" nzWidth="170px">结束时间</th>
          <th nzAlign="center" nzWidth="120px">状态</th>
          <th nzAlign="center" nzWidth="220px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 排序 -->
          <td nzAlign="center">
            {{ tableParams.pageSize * (tableParams.page - 1) + index + 1 }}
          </td>
          <!-- 名称 -->
          <td nzAlign="center">{{ data.word || '-' }}</td>
          <!-- 标签 -->
          <td nzAlign="center">
            <img
              nz-image
              width="42px"
              height="42px"
              [nzFallback]="fallback"
              [nzSrc]="data.hpicUrl"
              alt=""
            />
          </td>
          <!-- 应用ID -->
          <td nzAlign="center">{{ data.appId || '-' }}</td>
          <!-- 开始时间 -->
          <td nzAlign="center">{{ data.beginTime || '-' }}</td>
          <!-- 结束时间 -->
          <td nzAlign="center">{{ data.endTime || '-' }}</td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.status | gameHotType: 'color'}">
              {{ data.status | gameHotType: 'label' }}
            </span>
          </td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <button
              nz-button
              nzType="link"
              nzSize="small"
              [disabled]="setMoveDisabled(index, 1)"
              (click)="moveItemData(data, 1)"
            >上移</button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              [disabled]="setMoveDisabled(index, 2)"
              (click)="moveItemData(data, 0)"
            >下移</button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="showEditModal(data)"
            >编辑</button>

            <button
              nz-button
              nzType="link"
              nzSize="small"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认删除?"
              (nzOnConfirm)="deleteItemData(data)"
            >删除</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 新建编辑 -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzWidth]="720"
  [nzFooter]="null"
  [(nzVisible)]="isVisible"
  [nzTitle]="modalItem ? '编辑' : '新增'"
  (nzOnCancel)="isVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <form nz-form [formGroup]="validateForm">
        <nz-form-item>
          <nz-form-label nzFlex="100px" nzRequired>名称</nz-form-label>
          <nz-form-control nzFlex="236px" nzErrorTip="请输入名称!">
            <input
              nz-input
              placeholder="请输入名称"
              formControlName="word"
            />
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzFlex="100px">标签</nz-form-label>
          <nz-form-control nzFlex="auto">
            <zdy-upload formControlName="hpicUrl"></zdy-upload>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzFlex="100px" nzRequired>应用ID</nz-form-label>
          <nz-form-control nzFlex="236px" nzErrorTip="请选择应用ID!">
            <nz-select
              nzShowSearch
              nzAllowClear
              nzPlaceHolder="请选择应用ID"
              formControlName="appId">
              <nz-option
                *ngFor="let option of gameAppOptions"
                nzCustomContent
                [nzLabel]="option.id"
                [nzValue]="option.id">
                <b>{{ option.id }}</b>
                <span class="p-l-8" style="color: #909399;">{{ option.name }}</span>
              </nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>

        <div nz-row>
          <nz-form-item nz-col nzSpan="12" style="display: flex;">
            <nz-form-label nzFlex="100px" nzRequired>开始时间</nz-form-label>
            <nz-form-control nzErrorTip="请选择开始时间!">
              <nz-date-picker
                style="width: 100%;"
                nzShowTime
                nzFormat="yyyy-MM-dd HH:mm:ss"
                formControlName="beginTime"
                nzPlaceHolder="开始时间"
                (ngModelChange)="timeChange($event, 'beginTime')"
              ></nz-date-picker>
            </nz-form-control>
          </nz-form-item>

          <nz-form-item nz-col nzSpan="12" style="display: flex;">
            <nz-form-label nzFlex="100px" nzRequired>结束时间</nz-form-label>
            <nz-form-control nzErrorTip="请选择结束时间!">
              <nz-date-picker
                style="width: 100%;"
                #endDatePicker
                nzShowTime
                nzFormat="yyyy-MM-dd HH:mm:ss"
                formControlName="endTime"
                nzPlaceHolder="结束时间"
                (ngModelChange)="timeChange($event, 'endTime')"
              ></nz-date-picker>
            </nz-form-control>
          </nz-form-item>
        </div>
      </form>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="default" (click)="isVisible = false">取消</button>
        <button nz-button nzType="primary" [nzLoading]="submitLoading" (click)="submitForm()">确定</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 新建编辑 -->